﻿Imports WiremetModel.Entities.SupplyOrders
Imports CrystalDecisions.CrystalReports.Engine

Public Class WireOrderReportService
    Inherits OrderReportService

    Public Function GenerateReport(ByVal wireOrder As WireOrder) As ReportDocument

        Dim wireOrderReport As New WireOrderReport()

        Dim wireOrderReportData As New List(Of WireOrderLineReportDataRow)
        For Each wireOrderLine As WireOrderLine In wireOrder.OrderLines.OrderBy(Function(x) x.Diameter)
            wireOrderReportData.Add(New WireOrderLineReportDataRow With {
                                    .Diameter = wireOrderLine.Diameter.ToString(),
                                    .DiameterToleranceMinus = wireOrderLine.DiameterToleranceMinus.ToString(),
                                    .DiameterTolerancePlus = wireOrderLine.DiameterTolerancePlus.ToString(),
                                    .EnduranceMax = wireOrderLine.EnduranceMax.ToString(),
                                    .EnduranceMin = wireOrderLine.EnduranceMin.ToString(),
                                    .Id = wireOrderLine.Id,
                                    .MaterialGrade = wireOrderLine.MaterialGrade.NazwaAng,
                                    .MeasureUnit = wireOrderLine.MeasureUnit.Jednostka,
                                    .Packaging = If(IsNothing(wireOrderLine.Packaging), String.Empty, wireOrderLine.Packaging.Nazwa),
                                    .Quantity = wireOrderLine.Quantity,
                                    .UnitPrice = wireOrderLine.UnitPrice
                               })
        Next

        wireOrderReport.SetDataSource(wireOrderReportData)
        SetParameterValues(wireOrder, wireOrderReport)
        Return wireOrderReport

    End Function

End Class
